library(MASS)
library(Zelig)
library(MNP)
#library(scatterplot3d)
#rm(list=ls())
setwd("C:/WTO_Midwest/")


#remove(list=ls())
#load("C:\\WTO_Midwest\\Analysis\\Interact_2013_03_27_long_PEUE")

##############################################
# Making Plots- Substantive Effects
##############################################


load("C:\\WTO_Midwest\\Analysis\\Interact_2013_03_30_long_PEUE1")
write.table(se_m1_full_pe1,file="se_m1_full_pe1.csv",sep=",",row.names=F)
remove(list=ls())
load("C:\\WTO_Midwest\\Analysis\\Interact_2013_03_30_long_PEUE0")
write.table(se_m1_full_pe0,file="se_m1_full_pe0.csv",sep=",",row.names=F)
remove(list=ls())

se_m1_full_pe1 <- read.csv(file="se_m1_full_pe1.csv",head=TRUE,sep=",")
se_m1_full_pe0 <- read.csv(file="se_m1_full_pe0.csv",head=TRUE,sep=",")


#####
# Effects of UE on Pr(WTO), for PE1 PE0
#####


plot(se_m1_full_pe1[,1],se_m1_full_pe1[,4],
		type="l", ylim=c(0,0.002), main="Effects of U.S. Unemployment on Pr(WTO Dispute)", xlab="U.S. Unemployment Rate", ylab="Predicted Probability of WTO Dispute", col=3)
	lines(smooth.spline(se_m1_full_pe1[,1],se_m1_full_pe1[,7], df=35), col=3)
	lines(smooth.spline(se_m1_full_pe1[,1],se_m1_full_pe1[,10], df=35), col=3)
	lines(se_m1_full_pe0[,1],se_m1_full_pe0[,4], type="l", col=4)
	lines(smooth.spline(se_m1_full_pe0[,1],se_m1_full_pe0[,7], df=35), col=4)
	lines(smooth.spline(se_m1_full_pe0[,1],se_m1_full_pe0[,10], df=35), col=4)
	legend("top", c("Election Year", "Non-election Year"), col = c(3,4),
		lty = c(1, 1), merge = FALSE, bg = 'gray90')
dev.print(postscript, "C:/WTO_Midwest/Drafts/CAver_MNP_UE_6_m3_0401.eps", horizontal=FALSE)


#####
# Effects of UE on Pr(Revoke), for PE1 PE0
#####
plot(se_m1_full_pe1[,1],se_m1_full_pe1[,3],
		type="l", ylim=c(0,0.010), main="Effects of U.S. Unemployment on Pr(Unil. Removal)", xlab="U.S. Unemployment Rate", ylab="Predicted Probability of WTO Dispute", col=3)
	lines(smooth.spline(se_m1_full_pe1[,1],se_m1_full_pe1[,6], df=35), col=3)
	lines(smooth.spline(se_m1_full_pe1[,1],se_m1_full_pe1[,9], df=35), col=3)
	lines(se_m1_full_pe0[,1],se_m1_full_pe0[,3], type="l", col=4)
	lines(smooth.spline(se_m1_full_pe0[,1],se_m1_full_pe0[,6], df=35), col=4)
	lines(smooth.spline(se_m1_full_pe0[,1],se_m1_full_pe0[,9], df=35), col=4)
	legend("top", c("Election Year", "Non-election Year"), col = c(3,4),
		lty = c(1, 1), merge = FALSE, bg = 'gray90')
dev.print(postscript, "C:/WTO_Midwest/Drafts/CAver_MNP_UE_3_m3_0401.eps", horizontal=FALSE)



#########################################
# Effects of EX on Pr(WTO)/PR(UR)
#########################################
remove(list=ls())
load("C:\\WTO_Midwest\\Analysis\\Interact_2013_03_30_long_EX")

plot(se_m3_full_ex[,1],se_m3_full_ex[,4],
		type="l", ylim=c(0,0.005), main="Effects of U.S. Exports on Probability of Exit", xlab="U.S. Exports", ylab="Predicted Probability", col=3)
	lines(se_m3_full_ex[,1],se_m3_full_ex[,3], type="l", col=4)
	lines(smooth.spline(se_m3_full_ex[,1],se_m3_full_ex[,6], df=20), col=4)
	lines(smooth.spline(se_m3_full_ex[,1],se_m3_full_ex[,7], df=20), col=3)
	lines(smooth.spline(se_m3_full_ex[,1],se_m3_full_ex[,9], df=20), col=4)
	lines(smooth.spline(se_m3_full_ex[,1],se_m3_full_ex[,10], df=20), col=3)
	legend("top", c("WTO Dispute", "Unil. Removal"), col = c(3,4),
		lty = c(1, 1), merge = FALSE, bg = 'gray90')
dev.print(postscript, "C:/WTO_Midwest/Drafts/CAver_MNP_EX_36_m3_0401.eps", horizontal=FALSE)




#########################################
# Effects of IM on Pr(WTO)/PR(UR)
#########################################
remove(list=ls())
load("C:\\WTO_Midwest\\Analysis\\Interact_2013_03_30_long_IM")

plot(se_m3_full_im[,1],se_m3_full_im[,4], type="l", ylim=c(0,0.0055), main="", xlab="U.S. Imports", ylab="Predicted Probability", col=3)
	lines(smooth.spline(se_m3_full_im[,1],se_m3_full_im[,7], df=25), col=3)
	lines(smooth.spline(se_m3_full_im[,1],se_m3_full_im[,10], df=25), col=3)
	lines(se_m3_full_im[,1],se_m3_full_im[,3], type="l", col=4)
	lines(smooth.spline(se_m3_full_im[,1],se_m3_full_im[,6], df=25), col=4)
	lines(smooth.spline(se_m3_full_im[,1],se_m3_full_im[,9], df=25), col=4)
	legend("top", c("WTO Dispute", "Unil. Removal"), col = c(3,4),
		lty = c(1, 1), merge = FALSE, bg = 'gray90')
dev.print(postscript, "C:/WTO_Midwest/Drafts/CAver_MNP_IM_36_m3_0401.eps", horizontal=FALSE)




